package com.hzlx.tasks.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.tasks.domain.MesMaintenanceTasks;
import com.hzlx.tasks.service.IMesMaintenanceTasksService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备维护任务跟踪（记录维护工单全生命周期）Controller
 * 
 * @author ruoyi
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/equipment")
public class MesMaintenanceTasksController extends BaseController
{
    @Autowired
    private IMesMaintenanceTasksService mesMaintenanceTasksService;

    /**
     * 查询设备维护任务跟踪（记录维护工单全生命周期）列表
     */
    @RequiresPermissions("equipment-service:tasks:list")
    @GetMapping("/tasks/list")
    public TableDataInfo list(MesMaintenanceTasks mesMaintenanceTasks)
    {
        startPage();
        List<MesMaintenanceTasks> list = mesMaintenanceTasksService.selectMesMaintenanceTasksList(mesMaintenanceTasks);
        return getDataTable(list);
    }

    /**
     * 导出设备维护任务跟踪（记录维护工单全生命周期）列表
     */
    @RequiresPermissions("equipment-service:tasks:export")
    @Log(title = "设备维护任务跟踪（记录维护工单全生命周期）", businessType = BusinessType.EXPORT)
    @PostMapping("/tasks/export")
    public void export(HttpServletResponse response, MesMaintenanceTasks mesMaintenanceTasks)
    {
        List<MesMaintenanceTasks> list = mesMaintenanceTasksService.selectMesMaintenanceTasksList(mesMaintenanceTasks);
        ExcelUtil<MesMaintenanceTasks> util = new ExcelUtil<MesMaintenanceTasks>(MesMaintenanceTasks.class);
        util.exportExcel(response, list, "设备维护任务跟踪（记录维护工单全生命周期）数据");
    }

    /**
     * 获取设备维护任务跟踪（记录维护工单全生命周期）详细信息
     */
    @RequiresPermissions("equipment-service:tasks:query")
    @GetMapping(value = "/tasks/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(mesMaintenanceTasksService.selectMesMaintenanceTasksByTaskId(taskId));
    }

    /**
     * 新增设备维护任务跟踪（记录维护工单全生命周期）
     */
    @RequiresPermissions("equipment-service:tasks:add")
    @Log(title = "设备维护任务跟踪（记录维护工单全生命周期）", businessType = BusinessType.INSERT)
    @PostMapping("/tasks")
    public AjaxResult add(@RequestBody MesMaintenanceTasks mesMaintenanceTasks)
    {
        return toAjax(mesMaintenanceTasksService.insertMesMaintenanceTasks(mesMaintenanceTasks));
    }

    /**
     * 修改设备维护任务跟踪（记录维护工单全生命周期）
     */
    @RequiresPermissions("equipment-service:tasks:edit")
    @Log(title = "设备维护任务跟踪（记录维护工单全生命周期）", businessType = BusinessType.UPDATE)
    @PutMapping("/tasks")
    public AjaxResult edit(@RequestBody MesMaintenanceTasks mesMaintenanceTasks)
    {
        return toAjax(mesMaintenanceTasksService.updateMesMaintenanceTasks(mesMaintenanceTasks));
    }

    /**
     * 删除设备维护任务跟踪（记录维护工单全生命周期）
     */
    @RequiresPermissions("equipment-service:tasks:remove")
    @Log(title = "设备维护任务跟踪（记录维护工单全生命周期）", businessType = BusinessType.DELETE)
	@DeleteMapping("/tasks/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(mesMaintenanceTasksService.deleteMesMaintenanceTasksByTaskIds(taskIds));
    }
}
